<!DOCTYPE html>
<html>
{include file='/common/_meta'}
<body>
	<!-- 头部 -->
{include file='/common/top'}
	<!-- /头部 -->
<style>
    input{
        padding:3px 5px;
        border: none;
        border: solid 1px #ccc;
        border-radius: 5px;
    }
</style>
	<div class="main-container container-fluid">
		<div class="page-container">
			            <!-- Page Sidebar -->
                {include file='/common/left'}
            <!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <a href="{:url('Index/index')}">系统</a>
                        </li>
                        <li class="active">商品管理</li>
                    </ul>
                </div>
                <!-- /Page Breadcrumb -->

                <!-- Page Body -->
                <div class="page-body">
                    
<div class="row">
    <div class="col-lg-12 col-sm-12 col-xs-12">
        <div class="widget">
            <div class="widget-body">
                <form action="" method="post" >
                <div class="flip-scroll">
                    <table class="table table-bordered table-hover">
                        <thead class="">
                            <tr>
                                {volist name='attrContent' id='attrContents'}
                                    <th class="text-center" width="10%">{$key}</th>
                                {/volist}
                                <th class="text-center" width="14%">库存量</th>
                                <th class="text-center" width="14%">操作</th>
                            </tr>
                        </thead>
                        
                        <tbody>
                            <?php if ($productRes):?>
                                <?php foreach($productRes as $k2=>$v2):?>
                                <tr>
                                    <?php foreach($attrContent as $k=>$v):?>
                                        <td align="center">
                                            <select name="product_attr_type[{$k}][]" id="">
                                                <option value="">请选择</option>
                                                <?php foreach($v as $k1=>$v1):?>
                                                    <option value="<?php echo $v1['commattr_id'];?>"

                                                        <?php $attrValue = explode(',',$v2['product_commodity_attr_type']); ?>
                                                            <?php if (in_array($v1['commattr_id'],$attrValue)):?>
                                                                selected="selected"
                                                            <?php endif;?>

                                                    ><?php echo $v1['commattr_value'];?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </td>
                                    <?php endforeach;?>
                                    <td align="center">
                                        <input type="text" name="product_number[]" id="" value="<?php echo $v2['product_commodity_number']; ?>" />
                                    </td>
                                    <td align="center">
                                        
                                        <?php if ($k2 == 0) { echo '<button type="button" class="btn btn-sm btn-azure btn-addon" onClick="addtrlist(this);">+</button>'; }else{ echo '<button type="button" class="btn btn-sm btn-azure btn-addon" onClick="addtrlist(this);">-</button>'; }?>
                                        
                                    </td>
                                </tr>
                                <?php endforeach;?>
                            <?php else:?>
                                <tr>
                                    <?php foreach($attrContent as $k=>$v):?>
                                        <td align="center">
                                            <select name="product_attr_type[{$k}][]" id="">
                                                <option value="">请选择</option>
                                                <?php foreach($v as $k1=>$v1):?>
                                                    <option value="<?php echo $v1['commattr_id'];?>"><?php echo $v1['commattr_value'];?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </td>
                                    <?php endforeach;?>
                                    <td align="center">
                                        <input type="text" name="product_number[]" id="" />
                                    </td>
                                    <td align="center">
                                        <button type="button" class="btn btn-sm btn-azure btn-addon" onClick="addtrlist(this);">+</button>
                                    </td>
                                </tr>
                                 <?php endif;?>
                       </tbody>
                    </table>
                    <div class="flip-scroll" style="margin: 30px 5%; text-align: left;">
                        <button type="submit" class="btn btn-default">保存信息</button>
                    </div>
                </div>
                </form>
                <div> 
              	</div>
            </div>
        </div>
    </div>
</div>

                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
		</div>	
	</div>

	    <!--Basic Scripts-->
    {include file='/common/footer'}    
    <script src="__admin__/style/jquery.js"></script>
    <script type="text/javascript">
        function addtrlist(tr){
            var trs = $(tr).parent().parent();
            newtr = trs.clone();
            if ( $(tr).html() === '+' ){
                trs.find('button').html('-');
                trs.before( newtr );
            } else {
                trs.remove();
            }
        }
    </script>
</body>
</html>